package com.oba.base.dao;

import java.util.List;

import javax.faces.model.ListDataModel;

import com.oba.base.dao.pager.DefaultPageCallBack;
import com.oba.base.interfaces.IBaseBo;
import com.oba.base.interfaces.IHsqlBuilder;
import com.oba.base.interfaces.IPager;
import com.oba.base.interfaces.PageCallBack;

/**
 * 数据库分布数据对象
 * 
 * @author han
 * 
 */
public class DBDataModel extends ListDataModel {
	private static int DEFAULT_PAGE_SIZE = 10;
	private DBPager pager;

	private DBDataModel(boolean isMultiCheck, PageCallBack... pageCallBack) {
		if (pageCallBack == null) {
			pageCallBack = new DefaultPageCallBack[1];
		}
		pager = new DBPager(this, isMultiCheck, pageCallBack);
	}

	public IPager getPager() {
		return pager;
	}

	public static DBDataModel create(PageCallBack... pageCallBack) {
		return new DBDataModel(Boolean.FALSE, pageCallBack);
	}

	public static DBDataModel createMultiCheckPage(PageCallBack... pageCallBack) {
		return new DBDataModel(Boolean.TRUE, pageCallBack);
	}

	public void find(IHsqlBuilder hql, int pageSize) { 
		pager.setPageSize(pageSize);
		hql.build();
		pager.find(hql, hql.getDao());
	}

	public void find(IHsqlBuilder hql) {
		pager.setPageSize(DEFAULT_PAGE_SIZE);
		hql.build();
		pager.find(hql, hql.getDao());
	}

	public List<Long> getCheckedIds() {
		return pager.getCheckedIds();
	}

	public List<IBaseBo> getAllData() {
		return pager.getAllData();
	}

	public int getSerialCount() {
		return (pager.getCurPage() - 1) * pager.getPageSize() + this.getRowIndex() + 1;
	}
	
	public boolean equals(Object obj) {
		return false;
	}
	
}
